var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
var capArr=[]
function randomWord() {
    var str = "", arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    for (var i = 0; i < 20; i++) {
        var pos = Math.round(Math.random() * (arr.length - 1));
        str += arr[pos];
        if ((i + 1) % 4 == 0 && (i < 19)) {
            str += '-';
        }
    }
    return str;
}
;
function check(name, email, content) {
    var flag = true;
    var pos1 = document.getElementsByName('name')[0];
    var pos2 = document.getElementsByName('email')[0];
    var pos3 = document.getElementsByName('content')[0];
    var err = document.querySelectorAll('.err');
    if (name.length == 0) {
        flag = false;
        err[0].innerHTML = '名字 必须填写';
    }
    else {
        err[0].innerHTML = '';
    }
    if (email.length == 0) {
        flag = false;
        err[1].innerHTML = '邮箱 必须填写';
    }
    else if (!myreg.test(email)) {
        flag = false;
        err[1].innerHTML = '邮箱 格式不对';
    }
    else {
        err[1].innerHTML = '';
    }
    if (content.length == 0) {
        flag = false;
        err[2].innerHTML = '内容 必须填写';
    }
    else {
        err[2].innerHTML = '';
    }
    return flag;
}
function Isubmit(p) {
    var form = document.getElementsByTagName('form')[0];
    var formData = new FormData(form);
    var time = parseInt(String(formData.get('time')).replace(/[^0-9]/ig, ""));
    var name = formData.get('name');
    var email = formData.get('email');
    var content = formData.get('content');
    var tip = formData.get('tips');
    if (check( name, email, content)) {
        var cas = {
            id: randomWord(),
            name: name,
            email: email,
            time: time,
            content: content,
            tip: tip
        };
        p.disabled = true;
        p.value = '正在添加...';
        capArr.push(cas)
        console.log(capArr);
        var strCas = JSON.stringify(capArr);
        localStorage.setItem("__date__", strCas)
        window.location.href = 'put_done.html';
        return true;
    }
    else {
        return false;
    }
}